Passed
Push — main ( 67f6a3...fa9d82 )
by Andrii
02:11
created

utils.ts ➔ truthyKeys   A

Complexity

Conditions 3

Size

Total Lines 3
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 3
1
const stringifyProperty: SymbolConstructor["toPrimitive"] | "valueOf" | "toString"  = Symbol.toPrimitive
2
3
const {
4
  defineProperty: $defineProperty
5
} = Object
6
7
export {
8
 stringifyClassNamed, emptize
9
}
10
11
function stringifyClassNamed<T extends {className: string}>(source: T) :T {
12
  if (!source.hasOwnProperty(stringifyProperty))
13
    $defineProperty(source, stringifyProperty, {value: classNamedToString})
14
  
15
  return source
16
}
17
18
function classNamedToString(this: {className: string}) {
19
  return this.className
20
}
21
22
function emptize(source: undefined|Record<string, any>) {
23
  if (
24
    source
25
    && !source.hasOwnProperty(stringifyProperty)
26
  )
27
    $defineProperty(source, stringifyProperty, {value: emptyLambda})
28
  return source
29
}
30
31
function emptyLambda() {
32
  return "" as const
33
}
34